package game.gui 
{
	import com.greensock.TweenLite;
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import game.Game;
	import game.Player;
	/**
	 * ...
	 * @author Sulus Ltd.
	 */
	public class Gui extends Sprite
	{
		public var papa:Game;
		private var playerNameBanner:MovieClip;
		private var endTurnButton:SimpleButton;
		private var endTurnCallback:Function;
		
		public function Gui() 
		{
			
		}
		
		public function Init():void
		{
			
		}
		
		public function SetPhaseName(name:String,onAnimationFinishCallbak:Function):void
		{
			//create announce , show and kill, shoot and forget
			var announce:MovieClip = new phase_announce();
			addChild(announce);
			announce.x = (800 - announce.width) / 2;
			announce.y = (600 - announce.height) / 2;
			announce.alpha = 0;
			announce.turntext.text = "Turn " + String(papa.turn);
			announce.phasenametext.text = name;
			TweenLite.to(announce, 0.5, { alpha:1.0, onComplete:OnPhaseShitAppearComplete,onCompleteParams:[announce,onAnimationFinishCallbak] } );
		}
		
		private function OnPhaseShitAppearComplete(announce:MovieClip,callback:Function):void 
		{
			TweenLite.to(announce, 0.5, { alpha:0.0, onComplete:OnPhaseShitDisappaerComplete,onCompleteParams:[announce,callback],delay:1.0 } );
		}
		
		private function OnPhaseShitDisappaerComplete(announce:MovieClip,callback:Function):void 
		{
			removeChild(announce);
			callback();
		}
		
		public function SetCurrentPlayer(player:Player = null):void
		{
			//del old banna
			if (playerNameBanner)
			{
				removeChild(playerNameBanner);
				playerNameBanner  = null;
				
			}
			
			//show playa banner up there
			if (player)
			{
				playerNameBanner = new playername();
				if (player.uid>0 && player.uid<=playerNameBanner.totalFrames)
					playerNameBanner.gotoAndStop(player.uid);
				else
					playerNameBanner.gotoAndStop(1);
				playerNameBanner.nametext.text = player.name;	
				addChild(playerNameBanner);
				playerNameBanner.x = (800 - playerNameBanner.width) / 2;
				playerNameBanner.mouseChildren = playerNameBanner.mouseEnabled = false;
			}
			
		}
		
		public function ShowEndTurnButton(orly:Boolean,callback:Function=null):void
		{
			if (!endTurnButton)
			{
				endTurnButton = new endturn_button();
				endTurnButton.x = 587;
				endTurnButton.y = 540;
				addChild(endTurnButton);
				endTurnButton.addEventListener(MouseEvent.CLICK, OnEndTurnButtonClick, false, 0, true);
			}
			
			endTurnButton.visible = orly;
			endTurnCallback = callback;
			
		}
		
		private function OnEndTurnButtonClick(e:MouseEvent):void 
		{
			if (Boolean(endTurnCallback))
				endTurnCallback();
		}
		
		
	}

}